<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set('memory_limit', '1000M');
set_time_limit(0);
CONST TYPE_NORMAL = 1;
CONST TYPE_BAD = 2;
include_once('function.php');
include_once('sell.php');
include_once('rent.php');
$borough_file_name = 'borough';
$borough_file=file($borough_file_name);

function outputBadHouse($house_info, $bad_type){
    $house_info['bad_type'] = $bad_type;
    $out = json_encode($house_info);
    #echo $house_info['source_url']."\t".$out."#B\n";
}
$borough = array();
foreach($borough_file as &$line_json){
    $line = json_decode($line_json, True);
    $borough[$line['borough_name']] = 
	array('id'=>$line['id'], 'cityarea_id'=>$line['cityarea_id'], 'cityarea2_id'=>$line['cityarea2_id']);
}
$stat_array=array();
$source_array=array();
while (($line_json = fgets(STDIN)) !== false) {
    $borough_array=array();
    $line_json = trim($line_json);
    if(empty($line_json))
        continue;
    $house_info = json_decode($line_json, true);
    $house_info['tag'] = str_replace("12#", "", $house_info['tag']);
    
    //处理小区
    if ($borough[$house_info['borough_name']]){
	    $house_info['borough_id'] = $borough[$house_info['borough_name']]['id'];
        $house_info['cityarea_id'] = $borough[$house_info['borough_name']]['cityarea_id'];
        $house_info['cityarea2_id'] = $borough[$house_info['borough_name']]['cityarea2_id'];
    }
    else{
            if ($house_info['borough_name'] == '' || empty($house_info['borough_name']) || $house_info['borough_name'] ==NULL){
                #echo $house_info['source_url']."\n";
                #continue;
            }
            if (array_key_exists($house_info['source'], $stat_array)) {
                $borough_array=$source_array[$house_info['source']];
                if (!in_array($house_info['borough_name'], $borough_array)){
                    $stat_array[$house_info['source']] = $stat_array[$house_info['source']] + 1;
                    $borough_array[]=$house_info['borough_name'];
                    $source_array[$house_info['source']]=$borough_array;
                }
            }
            else{
                $stat_array[$house_info['source']] = 1;
                $borough_array=array($house_info['borough_name']);
                $source_array[$house_info['source']]=$borough_array; 
            }
        if ($house_info['source'] != 10){
            #echo $house_info['source']."\n";
            echo $house_info['borough_name']."\n";
        }
    }
}
#var_dump($stat_array);
/*$sum=0;
foreach ($stat_array as $key=>$value){
    echo $value."\t".$key."\n";
    $sum=$sum + $value;
}
echo "sum=".$sum."\n";*/
    

    
